package desktop;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class SetTeamName extends JPanel {
    private JTextField jTextField0 = new JTextField(10);
    private JTextField jTextField1 = new JTextField(10);
    private JTextField jTextField2 = new JTextField(10);

    SetTeamName(int i, Screen screen){
        JPanel jPanel0 = new JPanel();
        JLabel jLabel0 = new JLabel("组别名称：");
        jTextField0.setText("组别");
        JButton jButton0 = new JButton("确定");
        jButton0.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                screen.setGroupName(jTextField0.getText());
            }
        });
        screen.setGroupName("组别");
        jPanel0.add(jLabel0);
        jPanel0.add(jTextField0);
        jPanel0.add(jButton0);

        JPanel jPanel1 = new JPanel();
        JLabel jLabel1 = new JLabel("红队队名：");
        jTextField1.setText("红队");
        JButton jButton1 = new JButton("确定");
        jButton1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                screen.setTeam1Name(jTextField1.getText());
            }
        });
        screen.setTeam1Name("红队");
        jPanel1.add(jLabel1);
        jPanel1.add(jTextField1);
        jPanel1.add(jButton1);

        JPanel jPanel2 = new JPanel();
        JLabel jLabel2 = new JLabel("黄队队名：");
        jTextField2.setText("黄队");
        JButton jButton2 = new JButton("确定");
        jButton2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                screen.setTeam2Name(jTextField2.getText());
            }
        });
        screen.setTeam2Name("黄队");
        jPanel2.add(jLabel2);
        jPanel2.add(jTextField2);
        jPanel2.add(jButton2);

        this.setLayout(new GridLayout(3,1));
        this.setBorder(new TitledBorder("赛道"+i));
        this.add(jPanel0);
        this.add(jPanel1);
        this.add(jPanel2);
    }

    void setGroupName(String groupName){
        jTextField0.setText(groupName);
    }

    void setTeam1Name(String team1Name){
        jTextField1.setText(team1Name);
    }

    void setTeam2Name(String team2Name){
        jTextField2.setText(team2Name);
    }
}
